﻿// DesignPattern.cpp: 定义应用程序的入口点。
//

#include <sstream>
#include <algorithm>
#include "main.h"
#include "HandlerRegister.h"

using namespace std;

static std::string CommandOfLine(const std::string& commandLine)
{
	std::stringstream ss;
	ss << commandLine;
	std::string command;
	ss >> command;
	return command;
}

static void HandleCommandLine(const std::string& commandLine)
{
	auto command = CommandOfLine(commandLine);
	auto handler = HandlerRegister::Instance().GetHandler(command);
	if (handler != nullptr)
	{
		handler->Handle(commandLine);
	}
}

int main()
{
	std::string cmd;
	while (true)
	{
		cout << "[cmd] >> "; // can input space, stop when encounter Enter key '\n'
		std::getline(cin, cmd);
		if (cmd == "quit") break;
		HandleCommandLine(cmd);
	}

	return 0;
}
